<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/Liang34/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/Liang34/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/Liang34/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/Liang34/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/Liang34/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/Liang34/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/Liang34/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content=",,," />










<meta name="description" content="1.认识盒子边框的均分原理​    当元素的宽度和高度均设为0，并设置边框大小时，四个边框采用的是均分原理。如下面代码： 123456789#box1&amp;#123;            height: 0;            width: 0;            border-left: 10px solid red;            border-right: 10px solid">
<meta property="og:type" content="website">
<meta property="og:title" content="css中的三角形">
<meta property="og:url" content="https://liang34.github.io/Liang34/css/css%E4%B8%AD%E7%9A%84%E4%B8%89%E8%A7%92%E5%BD%A2.html">
<meta property="og:site_name" content="liang34">
<meta property="og:description" content="1.认识盒子边框的均分原理​    当元素的宽度和高度均设为0，并设置边框大小时，四个边框采用的是均分原理。如下面代码： 123456789#box1&amp;#123;            height: 0;            width: 0;            border-left: 10px solid red;            border-right: 10px solid">
<meta property="og:image" content="d:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing.png">
<meta property="og:image" content="d:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing2.png">
<meta property="og:image" content="d:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing3.png">
<meta property="og:image" content="d:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing4.png">
<meta property="og:image" content="d:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjaioxing5.png">
<meta property="article:published_time" content="2020-05-17T16:21:08.000Z">
<meta property="article:modified_time" content="2020-05-17T16:57:18.279Z">
<meta property="article:author" content="LiangJH">
<meta property="article:tag" content="css">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="d:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/Liang34/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://liang34.github.io/Liang34/css/css中的三角形.html"/>





  <title>css中的三角形 | liang34</title>
  








<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/Liang34/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">liang34</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/Liang34/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/Liang34/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/Liang34/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/Liang34/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    
    
    
    <div class="post-block page">
      <header class="post-header">

	<h1 class="post-title" itemprop="name headline">css中的三角形</h1>



</header>

      
      
      
      <div class="post-body">
        
        
          <h2 id="1-认识盒子边框的均分原理"><a href="#1-认识盒子边框的均分原理" class="headerlink" title="1.认识盒子边框的均分原理"></a>1.认识盒子边框的均分原理</h2><p>​    当元素的宽度和高度均设为0，并设置边框大小时，四个边框采用的是均分原理。如下面代码：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#box1</span>&#123;</span><br><span class="line">            <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">border-left</span>: <span class="number">10px</span> solid red;</span><br><span class="line">            <span class="attribute">border-right</span>: <span class="number">10px</span> solid yellow;</span><br><span class="line">            <span class="attribute">border-top</span>: <span class="number">10px</span> solid blue;</span><br><span class="line">            <span class="attribute">border-bottom</span>: <span class="number">10px</span> solid pink;</span><br><span class="line">        &#125;</span><br><span class="line">&lt;div id="box1"&gt;&lt;/div&gt;</span><br></pre></td></tr></table></figure>

<p>此时浏览器显示的是：</p>
<p><img src="D:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing.png" alt="sanjiaoxing"></p>
<h2 id="2-等腰三角形与直角三角形"><a href="#2-等腰三角形与直角三角形" class="headerlink" title="2.等腰三角形与直角三角形"></a>2.等腰三角形与直角三角形</h2><p>由此可见，四个边框各自占了一个三角形，所以我们要实现三角形只要将其他三个边框设置为transparent即可。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#box2</span>&#123;</span><br><span class="line">			<span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">			<span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">			<span class="attribute">border-style</span>: solid;</span><br><span class="line">			<span class="attribute">border-width</span>: <span class="number">10px</span>;</span><br><span class="line">			<span class="attribute">border-color</span>: transparent transparent 							  transparent deeppink;</span><br><span class="line">&#125;</span><br><span class="line">&lt;div id = "box2"&gt;&lt;/div&gt;</span><br></pre></td></tr></table></figure>

<p>此时浏览器显示为：</p>
<p><img src="D:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing2.png" alt="sanjiaoxing2"></p>
<p>这是个等腰三角形，当然，我们也可以通过调节边框宽度来得到直角三角形。代码如下：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#box3</span>&#123;</span><br><span class="line">            <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">border-style</span>: solid;</span><br><span class="line">            <span class="attribute">border-color</span>: transparent deeppink 									deeppink transparent;</span><br><span class="line">            <span class="attribute">border-width</span>: <span class="number">30px</span> <span class="number">20px</span> <span class="number">0</span> <span class="number">0</span>;<span class="comment">/*通过增加上边框来增加直角边*/</span></span><br><span class="line">        &#125;</span><br><span class="line">&lt;div id = "box3"&gt;&lt;/div&gt;</span><br></pre></td></tr></table></figure>

<p>浏览器显示为：</p>
<p><img src="D:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing3.png" alt="sanjiaoxing3"></p>
<h2 id="3-等腰三角形与直角三角形在网页开发的应用"><a href="#3-等腰三角形与直角三角形在网页开发的应用" class="headerlink" title="3.等腰三角形与直角三角形在网页开发的应用"></a>3.等腰三角形与直角三角形在网页开发的应用</h2><p>有时候我们需要搞一个带三角的盒子，这里就用到了等腰三角形如：</p>
<p><img src="D:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjiaoxing4.png" alt="sanjiaoxing4"></p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#box4</span>&#123;</span><br><span class="line">            <span class="attribute">position</span>: relative;</span><br><span class="line">            <span class="attribute">width</span>: <span class="number">60px</span>;</span><br><span class="line">            <span class="attribute">height</span>: <span class="number">100px</span>;</span><br><span class="line">            <span class="attribute">background-color</span>: pink;</span><br><span class="line">        &#125;</span><br><span class="line"><span class="selector-id">#box4</span> <span class="selector-tag">span</span>&#123;</span><br><span class="line">            <span class="attribute">position</span>: absolute;</span><br><span class="line">            <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">border-color</span>: transparent transparent 							  transparent pink;</span><br><span class="line">            <span class="attribute">border-style</span>: solid;</span><br><span class="line">            <span class="attribute">border-width</span>: <span class="number">10px</span>;</span><br><span class="line">            <span class="attribute">left</span>: <span class="number">60px</span>;</span><br><span class="line">            <span class="attribute">top</span>: <span class="number">10px</span>;</span><br><span class="line">        &#125;</span><br><span class="line">&lt;div id = "box4"&gt;&lt;/div&gt;</span><br></pre></td></tr></table></figure>

<p>直角三角形的应用：</p>
<p><img src="D:%5Cliang-bolg%5CLiang34.github.io%5Csource%5Ccss%5Csanjaioxing5.png" alt="sanjaioxing5"></p>
<p>在这个案例中主要用了直角三角形来是长方形分为两个梯形：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-id">#box5</span>&#123;</span><br><span class="line">            <span class="attribute">width</span>: <span class="number">200px</span>;</span><br><span class="line">            <span class="attribute">height</span>: <span class="number">25px</span>;</span><br><span class="line">            <span class="attribute">border-color</span>: tomato;</span><br><span class="line">            <span class="attribute">border-style</span>: solid;</span><br><span class="line">            <span class="attribute">color</span>: white;</span><br><span class="line">            <span class="attribute">font-weight</span>: <span class="number">700</span>;</span><br><span class="line">            <span class="attribute">text-align</span>: center;</span><br><span class="line">            <span class="attribute">line-height</span>: <span class="number">25px</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="selector-id">#box5</span> <span class="selector-class">.miaosha</span>&#123;</span><br><span class="line">            <span class="attribute">float</span>: left;</span><br><span class="line">            <span class="attribute">position </span>:relative;</span><br><span class="line">            <span class="attribute">background-color</span>: tomato;</span><br><span class="line">            <span class="attribute">width</span>:<span class="number">60%</span>;</span><br><span class="line">            <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="selector-id">#box5</span> <span class="selector-class">.miaosha</span> <span class="selector-tag">i</span>&#123;</span><br><span class="line">            <span class="attribute">height</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">position</span>: absolute;</span><br><span class="line">            <span class="attribute">border-style</span>: solid;</span><br><span class="line">            <span class="attribute">border-color</span>: transparent white transparent transparent;</span><br><span class="line">            <span class="attribute">border-width</span>: <span class="number">25px</span> <span class="number">10px</span> <span class="number">0</span> <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">right</span>: <span class="number">0</span>;</span><br><span class="line">            <span class="attribute">top</span>: <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="selector-class">.orign</span>&#123;</span><br><span class="line">            <span class="attribute">color</span>: gray;</span><br><span class="line">            <span class="attribute">text-decoration</span>: line-through;</span><br><span class="line">        &#125;</span><br><span class="line"> &lt;div id="box5"&gt;</span><br><span class="line">        &lt;span class="miaosha"&gt;￥1655</span><br><span class="line">            &lt;i&gt;&lt;/i&gt;</span><br><span class="line">        &lt;/span&gt;</span><br><span class="line">        &lt;span class="orign"&gt;￥2900&lt;/span&gt;</span><br><span class="line"> &lt;/div&gt;</span><br></pre></td></tr></table></figure>


        
      </div>
      
      
      
    </div>
    
    
    
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>	
  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/Liang34/images/avatar.jpg"
                alt="LiangJH" />
            
              <p class="site-author-name" itemprop="name">LiangJH</p>
              <p class="site-description motion-element" itemprop="description">前端,java</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/Liang34/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-认识盒子边框的均分原理"><span class="nav-number">1.</span> <span class="nav-text">1.认识盒子边框的均分原理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-等腰三角形与直角三角形"><span class="nav-number">2.</span> <span class="nav-text">2.等腰三角形与直角三角形</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-等腰三角形与直角三角形在网页开发的应用"><span class="nav-number">3.</span> <span class="nav-text">3.等腰三角形与直角三角形在网页开发的应用</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">LiangJH</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/Liang34/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/Liang34/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/Liang34/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/Liang34/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/Liang34/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/Liang34/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/Liang34/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/Liang34/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/Liang34/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

<script src="/Liang34/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/Liang34/live2dw/assets/hibiki.model.json"},"display":{"position":"right","width":145,"height":315},"mobile":{"show":true,"scale":0.5},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body>
</html>
